exception Houston

let vertex = ref (Array.init (!Sampling.nb_vertex + 1) 
  (function _ -> (0.,0.,0.)))
let face = ref ((Array.init !Sampling.nb_face) 
  (function _ -> (0,0,0)))

(* construit un tableau contenant tous les points de la carte *)
let get_vertex_tab file =
  let vertex_tab = Array.init (!Sampling.nb_vertex + 1)
    (function _ -> (0.0,0.0,0.0)) in
  let line = ref (input_line file) in
  while ((!line).[0] <> 'v') do
    line := input_line file;
  done;
  for i = 0 to (!Sampling.nb_vertex) - 1 do
    try
      Array.set vertex_tab (i+1) (MyConvert.vertex_of_string !line);
      line := input_line file;
    with
	End_of_file -> print_string "get_vertex_tab\n"
  done;
  (vertex_tab, file)

(* construit un tableau contenant toutes les faces de la carte *)
let get_face_tab file =
  let face_tab = Array.init (!Sampling.nb_face)
    (function _ -> (0,0,0)) in
  for i = 0 to (Array.length face_tab - 3) do
    try
      let line = input_line file in
      if (line.[0] = 'f') then
	Array.set face_tab i (MyConvert.int_triple_of_string line);
    with
	End_of_file -> print_string "get_face_tab\n"
  done;
  face_tab

let list_of_tab () =
  (Array.of_list !Sampling.vertex,
   Array.of_list !Sampling.face)
  
(* initialise les tableaux de points et de faces *)
let init_tab file_name =
  (*
  let file = open_in file_name in
  let (vertex_tab,file) = get_vertex_tab file in
  let face_tab = get_face_tab file in
  *)
  let (vertex_tab,face_tab) = list_of_tab () in
  begin
    vertex := vertex_tab;
    face := face_tab;
  end
